#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/27 9:34
from sqlmodel import Session, select

import common
import db
from api.entity import Case


class CaseService(object):
    @staticmethod
    def create_case(case: Case, session: Session, autocommit: bool = True):
        try:
            session.add(case)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建案件报错：{}', e)
            session.rollback()

    @staticmethod
    def get_latest_case(session: Session):
       case = session.exec(select(Case).order_by(Case.id.desc()).limit(1)).first()
       return case


